# Makefile
# Copyright (c) 2010 Peter Polacik <polacik.p@gmail.com>
#
# This file is part of Beix Operating System
# Licensed under MIT License, see COPYRIGHT for more information.

PROJECT = beix
V_MAJOR = 0
V_MINOR = 1
V_REL = alpha
VERSION = ${V_MAJOR}.${V_MINOR}${V_REL}
RELEASE = ${PROJECT}-${VERSION}
IMAGE = ${PROJECT}.img

CC = gcc
LINKER = ld
ASM = nasm

CFLAGS = -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I include -c -o
LDFLAGS = -T link.ld -o
ASFLAGS = -f elf -o

OBJ = start.o main.o screen.o gdt.o

.PHONY: all

all: ${RELEASE} ${OBJ}

# Cleaning, updating image and testing

clean:
	rm -f ${RELEASE} ${OBJ}

update:
	scripts/update-img.sh ${RELEASE} ${IMAGE}

# Linking

${RELEASE}: ${OBJ}
	${LINKER} ${LDFLAGS} ${RELEASE} ${OBJ}

# Object files compilation / assembly here ->

start.o:
	${ASM} ${ASFLAGS} start.o src/start.s

main.o:
	${CC} ${CFLAGS} main.o src/main.c

screen.o:
	${CC} ${CFLAGS} screen.o src/screen.c

gdt.o:
	${CC} ${CFLAGS} gdt.o src/gdt.c
